import { distinct, distinctUntilChanged, of } from "rxjs";

type BuildVersion = {
  engineVersion: string;
  transmissionVersion: string;
};

const totallyDifferentBuilds$ = of<BuildVersion[]>(
  { engineVersion: "1.1.0", transmissionVersion: "1.2.0" },
  { engineVersion: "1.1.0", transmissionVersion: "1.4.0" },
  { engineVersion: "1.3.0", transmissionVersion: "1.4.0" },
  { engineVersion: "1.3.0", transmissionVersion: "1.5.0" },
  { engineVersion: "2.0.0", transmissionVersion: "1.5.0" },
).pipe(
  // 非重复只保留最新
  distinctUntilChanged(compareFn),
);

// Logs:
// { engineVersion: '1.1.0', transmissionVersion: '1.2.0' }
// { engineVersion: '1.3.0', transmissionVersion: '1.4.0' }
// { engineVersion: '2.0.0', transmissionVersion: '1.5.0' }

function compareFn(prev: BuildVersion, curr: BuildVersion) {
  return (
    prev.engineVersion === curr.engineVersion ||
    prev.transmissionVersion === curr.transmissionVersion
  );
}

totallyDifferentBuilds$.subscribe(console.log);
